<?php
/*
Module Group: store
Module Group Name: 门店
Description: 门店模块用于展示门店信息
Version: 1.0
Iconurl: http://www.happyidea.com.cn/resource/wx_icon/default.png
Author: lr
Modules: store
Display: 1
*/

class storeModule extends Module{
	
	/*
	 * 在构造函数中装载所依赖的类或其他文件
	*/
	function __construct() {
		$this->includePhp('store', 'store');
	}

	/*
	 * 调用插件资源
	*/
	public function call($user, $method, $param) {
		switch ($method) {
			case 'getStoreDistrictArray':
				if(isset($param->id)){
					$id = $param->id;
				}
				if(isset($param->order)){
					$order = $param->order;
				} else {
					$order = "CONVERT( name USING gbk )";
				}
				if(isset($param->orderBy)){
					$orderBy = $param->orderBy;
				} else {
					$orderBy = "asc";
				}
				if(isset($param->start)){
					$start = $param->start;
				} else {
					$start = 0;
				}
				if(isset($param->limit)){
					$limit = $param->limit;
				} else {
					$limit = 10;
				}
				store::getStoreDistrictArray($id,$order,$orderBy,$start,$limit);
				break;
			case 'getPickupStoreDistrictArray':
				if(isset($param->id)){
					$id = $param->id;
				}
				if(isset($param->order)){
					$order = $param->order;
				} else {
					$order = "CONVERT( name USING gbk )";
				}
				if(isset($param->orderBy)){
					$orderBy = $param->orderBy;
				} else {
					$orderBy = "asc";
				}
				return store::getPickupStoreDistrictArray($id,$order,$orderBy);
				break;
			case 'getPickupStoreDistrict':
				if(isset($param->id)){
					$id = $param->id;
				}
				if(isset($param->order)){
					$order = $param->order;
				} else {
					$order = "CONVERT( name USING gbk )";
				}
				if(isset($param->orderBy)){
					$orderBy = $param->orderBy;
				} else {
					$orderBy = "asc";
				}
				store::getPickupStoreDistrict($id,$order,$orderBy);
				break;
			case 'getStoreDistrict': 
// 				$id=1;
				$order = "CONVERT( name USING gbk )";
				$orderBy = "asc";
				
				
				if(!isset($param->districtCategoryId)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				
				$districtCategoryId=$param->districtCategoryId;
				
				if(isset($param->id)){
					$id=$param->id;
				}
				if(isset($param->order)){
					$order = $param->order;
				}
				if(isset($param->orderBy)){
					$orderBy = $param->orderBy;
				}
				if(isset($param->start)){
					$start = $param->start;
				} else {
					$start = 0;
				}
				if(isset($param->limit)){
					$limit = $param->limit;
				} else {
					$limit = 10;
				}
				store::getStoreDistrict($districtCategoryId,$id,$order,$orderBy,$start,$limit);
				break;
			case 'getStoreList': 
				$order = "id";
				$orderBy = "asc";
				$start = 0;
				$limit = 10;
				$id = $param->id;
				//$userName = $user['userName'];
				
				if(!isset($id)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if(isset($param->order)){
					$order = $param->order;
				}
				if(isset($param->orderBy)){
					$orderBy = $param->orderBy;
				}
				if(isset($param->start)){
					$start = $param->start;
				}
				if(isset($param->limit)){
					$limit = $param->limit;
				}
				store::getStoreList($id,$order,$orderBy,$start,$limit);
				break;
			case 'getPickupStore':
				$districtId = $param->distid;
				if(!isset($districtId)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if(isset($param->order)){
					$order = $param->order;
				} else {
					$order = 'id';
				}
				if(isset($param->orderBy)){
					$orderBy = $param->orderBy;
				} else {
					$orderBy = 'asc';
				}
				store::getPickupStoreList($districtId,$order,$orderBy);
				break;
			case 'reserveSelNum':
				$id = $param->id;
				$userName = $user['userName'];

				if (!isset($id) || $userName == '') {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				
				store::reserveSelNum($id);
				break;
			case 'reserve':
				$id = $param->id;
				$personCount = $param->personCount;
				$reserveType = $param->reserveType;
				$reserveDate = $param->reserveDate;
				
				$userName = $user['userName'];

				if (!isset($id) || $userName == '') {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				
				store::reserve($id,$personCount,$reserveType,$reserveDate,$userName);
				break;
				
			case 'addReserve':
				$userName = $user['userName'];
				
				$storeId = $param->storeId;
				
				$fullName = $param->fullName;
				$phone = $param->phone;
				$personCount = $param->personCount;
				$remark = $param->remark;
				$reserveTime = $param->reserveTime;
				$reserveDate = $param->reserveDate;
				$reserveType = $param->reserveType;
				$storeResourceBaseId = $param->storeResourceBaseId;
				
				if (!isset($storeId) || $userName == '' || !isset($storeResourceBaseId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				
				store::addReserve($storeId,$userName,$fullName,$phone,$reserveTime,$reserveDate,$reserveType,$personCount,$remark,$storeResourceBaseId);
				break;
			case 'getStoreReserveOrders':
				$userName = $user['userName'];
				$storeId = $param->id;
				
				$start = $param->start;
				
				if (!isset($storeId) || $userName == '') {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if (!isset($start)) {
					$start = 0;
				}
				store::getStoreReserveOrders($storeId,$userName,$start);
				break;
			case 'getStoreReserveOrderDetail':
				$userName = $user['userName'];
				$id = $param->id;
				
				if (!isset($id) || $userName == '') {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				store::getStoreReserveOrderDetail($id,$userName);
				break;
			case 'getStoreReserveOrder':
// 				$userName = $user['userName'];
				$id = $param->id;
				$fromUserName = $param->fromUserName;
				$fullName = $param->fullName;
				
				if (!isset($id) || !isset($fromUserName) || !isset($fullName)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				$result = store::getStoreReserveOrder($id,$fromUserName,$fullName);
				return $result;
				break;
				
			case 'getStoreDetail':
				$id = $param->id;
				if (!isset($id) ) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				store::getStoreDetail($id);
				break;
			case 'baiduMap':
				$id = $param->id;
				if (!isset($id) ) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				store::baiduMap($id);
				break;
			case "allStore":
				store::allStore();
				break;
			case "storeList":
				$latitude = $param->latitude;
				$longitude = $param->longitude;
				if(!$latitude||!$longitude){
					Output::instance()->resultCode(1,"定位失败");
					return;
				}
				$search = $param->search;
				$province = $param->province;
				$city = $param->city;
				$juli = $param->juli;
				$serviceId = $param->serviceId;
				$order = $param->order;
				$start = $param->start;
				$limit = $param->limit;
				store::storeList($search,$latitude,$longitude,$province,$city,$serviceId,$juli,$order,$start,$limit);
				break;
		}
	}
}

$module = new storeModule();
Module::addModule($module);
?>